﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Drawing;

namespace blackhouse.Web {
	public static class WebKeys {

		public static string GetConfigValue(string key, string valueIfEmpty) {
			string value = ConfigurationManager.AppSettings[key];
			if(string.IsNullOrEmpty(value)) value = valueIfEmpty;
			return value;
		}

		public static int GetConfigValue(string key, int valueIfEmpty) {
			int value;
			if(Int32.TryParse(GetConfigValue(key, ""), out value))
				return value;
			else return valueIfEmpty;
		}

		public static string GetRequestValue(string key, string valueIfEmpty) {
			if(HttpContext.Current != null && HttpContext.Current.Request != null) {
				string value = HttpContext.Current.Request[key];
				if(string.IsNullOrEmpty(value)) value = valueIfEmpty;
				return value;
			} else return valueIfEmpty;
		}

		public static int GetRequestValue(string key, int valueIfEmpty) {
			int value;
			if(Int32.TryParse(GetRequestValue(key, ""), out value))
				return value;
			else return valueIfEmpty;
		}

	}
}